package com.slt.developkitweb.controler.swagger;

import com.slt.developkitpersistent.dto.StudentDTO;
import com.slt.developkitpersistent.model.result.AjaxResult;
import com.slt.developkitpersistent.vo.StudentVO;
import com.slt.developkitweb.annotation.ShowAPI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 一个简单的Controller来测试Swagger
 *
 * @author shalongteng
 * @version 1.0
 */
//@ApiResponses(value = {
//        @ApiResponse(
//                responseCode = "200",
//                description = "响应成功",
//                content = @Content(
//                        mediaType = "application/json",
//                        schema = @Schema(
//                                title = "AjaxResul和StudentVO组合模型",
//                                description = "返回实体，AjaxResult内data为StudentVO模型",
//                                anyOf = {AjaxResult.class, StudentVO.class})
//                )
//        ),
//        @ApiResponse(
//                responseCode = "500",
//                description = "响应失败",
//                content = @Content(
//                        mediaType = "application/json",
//                        schema = @Schema(
//                                title = "AjaxResul模型",
//                                description = "返回实体，AjaxResult内data为空",
//                                implementation = AjaxResult.class)
//                )
//        )
//})
@ShowAPI
@RestController
//@Tag(name = "OpenAPI3接口")
@Api(tags = "OpenAPI3接口")
@RequestMapping("/openAPI")
public class OpenAPI3Controller {

    /***
     * 根据ID查询学生信息（单条）
     * @param id 学生id
     * @return 返回一条数据
     */
    @Operation(summary = "get方法restful 传值",
            description = "get方法restful 传值，根据ID查询学生信息，并返回响应结果信息")
    @Parameter(name = "id", description = "学生ID", required = true, example = "1")
    @GetMapping("/testGet1/{id}")
    public AjaxResult<StudentVO> testGet1(@PathVariable(value = "id") Long id) {
        //模拟学生数据
        List<String> likes = Arrays.asList("抓鱼", "爬山", "写字");
        StudentVO studentVO = new StudentVO(id, "张三", 22, "安徽六安", 93.5, likes);
        return new AjaxResult(200, "成功", studentVO);
    }


    /***
     * 学生添加接口
     * @param studentDTO 学生DTO信息
     * @return 成功信息
     */
    @Operation(summary = "post body里传值")
    @PostMapping("/testPost1")
    public AjaxResult testPost1(@RequestBody StudentDTO studentDTO) {
        System.out.println("成功添加数据：" + studentDTO);
        return new AjaxResult(200, "成功", null);
    }

}
